<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/19
 * Time: 10:42
 */
namespace work{
    use app\ctr;
    use C\lib\Db;
    use C\mod\wprice;
    use C\mod\proute;
    class statistics extends ctr{
        /*
         * 累计收益
         */
        public function allSta(){
            Db::connect();

            if(($post=$this->getAesPost()) && ($worker=$this->getLogWorker())){
//                $data=[];
//                $all=Db::query('select count(id) AS num from bd_proute WHERE worker_id='.$worker->id.' AND remark = 1');
//                $data = $all->fetch(\PDO::FETCH_ASSOC);

                //收益
               // $allprice=Db::query('select price from bd_wprice WHERE worker_id='.$worker->id.' AND remark != 5');
                $allprice=Db::query('select price from bd_wprice WHERE worker_id='.$worker->id);
                $price = $allprice->fetch(\PDO::FETCH_ASSOC);
                if(empty($price['price'])){
                    $data['price']=0.00;
                }else{
                    $data['price']=$price['price'];
                }
                //var_dump($data);exit();
                //件数num
                $allNum=Db::query('select count(id) AS num from bd_order WHERE worker_id='.$worker->id.' AND state=2');
                $dataN= $allNum->fetch(\PDO::FETCH_ASSOC);
                $data['num']=$dataN['num'];

                //奖励
                $dStaj=Db::query('select SUM(price) as price from bd_proute WHERE worker_id='.$worker->id.' AND remark = 1');
                $dataj= $dStaj->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataj['price'])){
                    $data['award']=0.00;
                } else{
                    $data['award'] = $dataj['price'];
                }

                //罚款
                $dStaf=Db::query('select SUM(price) as price from bd_proute WHERE worker_id='.$worker->id.' AND remark = 2');
                $dataf= $dStaf->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataf['price'])){
                    $data['fine']=0.00;
                }else{
                    $data['fine'] = $dataf['price'];
                }
                //var_dump($data);exit;
                $this->writeAesJson(1,[
                    'data'=>$data
                ],1);
            }

        }
        /*
         * 一天收益
         */
        public function dateSta(){

            if(($post=$this->getAesPost()) && ($worker=$this->getLogWorker())){

                $data= [];
                $start_time=strtotime(date('Y-m-d',time()));
                $end_time=strtotime(date('Y-m-d',time()).' '.'23:59:59');
                $dSta=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark != 2 AND remark != 5');
                $data = $dSta->fetch(\PDO::FETCH_ASSOC);
                if(empty($data['price'])){
                    $data['price']=0.00;
                }

                //件数num
                $allNum=Db::query('select count(id) AS num from bd_order WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND state=2');
                $dataN= $allNum->fetch(\PDO::FETCH_ASSOC);
                $data['num']=$dataN['num'];
                //奖励
                $dStaj=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark = 1');
                $dataj= $dStaj->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataj['price'])){
                    $data['award']=0.00;
                } else{
                    $data['award'] = $dataj['price'];
                }

                //罚款
                $dStaf=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark = 2');
                $dataf= $dStaf->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataf['price'])){
                    $data['fine']=0.00;
                }else{
                    $data['fine'] = $dataf['price'];
                }

                $this->writeAesJson(1,[
                    'data'=>$data
                ],1);
            }

        }
        /*
         * 月收益
         */
        public function monthSta(){
            if(($post=$this->getAesPost()) && ($worker=$this->getLogWorker())){
                $data= [];
                $start_time=strtotime(date('Y-m-d',time()));
                $end_time=strtotime(date('Y-m-d',time()+30*60*60*24));

                $dSta=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark != 2 AND remark != 5');
                $data = $dSta->fetch(\PDO::FETCH_ASSOC);
                if(empty($data['price'])){
                    $data['price']=0.00;
                }
                //件数num
                $allNum=Db::query('select count(id) AS num from bd_order WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND state=2');
                $dataN= $allNum->fetch(\PDO::FETCH_ASSOC);
                $data['num']=$dataN['num'];
                //奖励
                $dStaj=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark = 1');
                $dataj= $dStaj->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataj['price'])){
                    $data['award']=0.00;
                } else{
                    $data['award'] = $dataj['price'];
                }

                //罚款
                $dStaf=Db::query('select SUM(price) as price from bd_proute WHERE time_add>='.$start_time.' AND time_add<='.$end_time.' AND worker_id='.$worker->id.' AND remark = 2');
                $dataf= $dStaf->fetch(\PDO::FETCH_ASSOC);
                if(empty($dataf['price'])){
                    $data['fine']=0.00;
                }else{
                    $data['fine'] = $dataf['price'];
                }
                $this->writeAesJson(1,[
                    'data'=>$data
                ],1);
            }

        }
    }
}